package com.corticon.client.validation;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.validation.Errors;

import com.corticon.client.model.DialogReportInput;
import com.corticon.client.util.ValidationUtils;

public class DialogReportValidator extends GenericHibernateValidator<DialogReportInput> {
	public DialogReportValidator(ValidationMessageFormatter validationMessageFormatter) {
		super.validationMessageFormatter = validationMessageFormatter;
	}

	@Override
	protected void complexValidate(Object object, Errors errors) {
		super.complexValidate(object, errors);
		DialogReportInput validator = (DialogReportInput) object;
		ValidationUtils validationUtils = new ValidationUtils();

		if (StringUtils.isEmpty(validator.getDialogInstanceId()) == true) {
			if (StringUtils.isEmpty(validator.getSessionId()) == true) {
				errors.rejectValue("dialogInstanceId", "E00001", "default message");
			}
		}
		if (StringUtils.isEmpty(validator.getSessionId()) == true) {
			if (StringUtils.isEmpty(validator.getDialogInstanceId()) == true) {
				errors.rejectValue("sessionId", "E00001", "default message");
			}
		}
		if (StringUtils.isEmpty(validator.getDialogInstanceId()) == false) {
			if (validator.getDialogInstanceId() == null && validationUtils.checkLongCharacters(validator.getDialogInstanceId()) == false) {
				errors.rejectValue("dialogInstanceId", "E00001", "default message");
			}
		}
		List<Character> vocabularyExcludedChars = new ArrayList<Character>();
		vocabularyExcludedChars.add('_');
		if (StringUtils.isEmpty(validator.getDialogInstanceId()) == false) {
			String[] nameArgs = { "dialogInstanceId" };
			commonCharactersValidate(validator.getDialogInstanceId(), vocabularyExcludedChars, errors, "dialogInstanceId", "E00001", nameArgs, "default message");
		}
		if (StringUtils.isEmpty(validator.getSessionId()) == false) {
			String[] nameArgs1 = { "sessionId" };
			commonCharactersValidate(validator.getSessionId(), vocabularyExcludedChars, errors, "sessionId", "E00001", nameArgs1, "default message");
		}
	}
}
